package com.kx.controller;

import com.kx.bean.Admin;
import com.kx.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
public class AdminController {
    @Autowired
    private AdminService adminService;

    @RequestMapping("loginValidate")
    @ResponseBody
    public int loginValidate(String username, String password, HttpSession session) {
        Admin admin = adminService.selectByUsernameAndPassword(username, password);
        ModelAndView mv = new ModelAndView();
        session.setAttribute("admin", admin);
        mv.setViewName("index");
//        mv.addObject("username",admin.getUsername());
        if (admin != null) {
            return 1;
        }
        return 0;
    }

    @RequestMapping("/find")
    @ResponseBody
    public Object find(Integer mid) {
        Admin admin = adminService.selectAll(mid);
        return admin;
    }

}
